package hernanbosqued.parking;

import java.lang.reflect.Type;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import android.os.Handler;
import android.os.Message;

public class JavascriptBridge
{
	private Handler handler;
	
	public JavascriptBridge( Handler p_handler )
	{
		handler = p_handler;
	}
	
	public void getParkings( String p_param )
	{		
		Message message = handler.obtainMessage( );

		try
		{
			Type listType = new TypeToken<Object[][]>( ){}.getType( );		
			Object[][] data = new Gson( ).fromJson( p_param, listType );
			
			message.what = HandlerMain.UPDATE_UI;
			message.obj =  data;		
		}
		catch( Exception err )
		{
			message.what = HandlerMain.ERROR;
		}
		finally
		{
			message.sendToTarget( );
		}	
	}
}
